<!DOCTYPE html>
<html lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>read_serial [HALCON算子参考手册]</title>
<style type="text/css">
      body {
    color: #000000;
    background-color: #ffffff;
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
}

.body_main {
    margin-left: 35px;
    margin-right: 35px;
}

@media screen and (min-width:992px) {

    .body_main {
        margin-left: 10%;
        margin-right: 10%;
    }

    table.toctable {
        width: 80%
    }
}

@media screen and (min-width:1400px) {

    .body_main {
        margin-left: 15%;
        margin-right: 15%;
    }

    table.toctable {
        width: 70%
    }
}

body>div ul ul {
    margin-left: inherit;
}

a:link {
    color: #0044cc;
}

a:link,
a:visited {
    text-decoration: none;
}

a:link:hover,
a:visited:hover {
    text-decoration: underline;
}

th {
    text-align: left;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    text-rendering: optimizeLegibility;
    color: #666666;
}

code {
    font-family: monospace,monospace;
}

h1 a.halconoperator {
    font-family: Arial, Helvetica, sans-serif;
    color: #666666;
}

h2 a.halconoperator {
    font-family: Arial, Helvetica, sans-serif;
    color: #666666;
}

hr {
    border: 0;
    border-top: solid 1px #f28d26;
}

.pre {
    display: block;
    padding-bottom: 1ex;
    font-family: monospace;
    white-space: pre;
}

pre {
    font-family: monospace, monospace;
    padding: 1ex;
    white-space: pre-wrap;
}

.toc {
    font-size: 80%;
    border-top: 1px dashed #f28d26;
    border-bottom: 1px dashed #f28d26;
    padding-top: 5px;
    padding-bottom: 5px;
}

.inv {
    margin: 0;
    border: 0;
    padding: 0;
}

.banner {
    color: #666666;
    padding-left: 1em;
}

.logo {
    background-color: white;
}

.keyboard {
    font-size: 80%;
    padding-left: 3px;
    padding-right: 3px;
    border-radius: 5px;
    border-width: 1px;
    border-style: solid;
    border-color: #f28d26;
    background-color: #f3f3f3;
}

.warning {
    margin-top: 2ex;
    margin-bottom: 1ex;
    padding: 10px;
    text-align: center;
    border: 1px solid;
    color: #bb0000;
    background-color: #fff7f7
}

.imprint {
    margin-top: 1ex;
    font-size: 80%;
    color: #666666;
}

.imprinthead {
    font-weight: bolder;
    color: #666666;
}

.indexlink {
    text-align: right;
    padding-bottom: 5px;
}

.postscript {
    margin-top: 2ex;
    font-size: 80%;
    color: #666666
}

.evenrow {
    background-color: #e7e7ef;
    vertical-align: top;
}

.oddrow {
    background-color: #f7f7ff;
    vertical-align: top;
}

.headrow {
    background-color: #97979f;
    color: #ffffff;
    vertical-align: top;
}

.logorow {
    vertical-align: top;
}

.error {
    color: red;
}

.var {
    font-style: italic
}

.halconoperator {
    font-family: monospace, monospace;
}

span.operator {
    font-family: monospace, monospace;
}

span.procedure {
    font-family: monospace, monospace;
}

span.operation {
    font-family: monospace, monospace;
}

span.feature {
    font-family: Arial, Helvetica, Homerton, sans-serif;
}

ul {
    padding-left: 1.2em;
}

li.dot {
    list-style-type: square;
    color: #f28d26;
}

.breadcrumb {
    font-size: 80%;
    color: white;
    background-color: #062d64;
    margin-bottom: 20px;
    padding-left: 35px;
    padding-right: 35px;
    padding-bottom: 15px;
}

.webbar {
    font-size: 80%;
    background-color: #dddddd;
    margin-top: 0px;
    margin-left: -35px;
    margin-right: -35px;
    margin-bottom: 0px;
    padding-top: 5px;
    padding-left: 35px;
    padding-right: 35px;
    padding-bottom: 5px;
}

.footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    border-top: 1px dashed #f28d26;
    font-size: 80%;
    color: #666666;
    padding-bottom: 8px;
}

.footer .socialmedia a {
    padding-left: 7px;
}

.socialmedia {
    padding-top: 10px;
}

.copyright {
    margin-top: 19px;
}

.breadcrumb a {
    color: #ffffff;
    border-bottom: 1px solid white;
}

.breadcrumb a:link:hover,
.breadcrumb a:visited:hover {
    text-decoration: none;
    border-bottom: none;
}

.heading {
    margin-top: 1ex;
    font-size: 110%;
    font-weight: bold;
    color: #666666;
}

.text {
    color: black;
}

.example {
    font-size: 80%;
    background-color: #f3f3f3;
    border: 1px dashed #666666;
    padding: 10px;
}

.displaymath {
    display: block;
    text-align: center;
    margin-top: 1ex;
    margin-bottom: 1ex;
}

.title {
    float: left;
    padding-top: 3px;
    padding-bottom: 3px;
}

.signnote {
    font-family: Arial, Helvetica, Homerton, sans-serif;
    font-size: 80%;
    color: #666666;
    font-weight: lighter;
    font-style: italic
}

.par {
    margin-bottom: 1.5em;
}

.parhead {
    text-align: right;
}

.parname {
    float: left;
}

.pardesc {
    font-size: 85%;
    margin-top: 0.5em;
    margin-bottom: 0.5em;
    margin-left: 2em;
}

.parcat {
    color: #666;
    font-weight: bold;
}

*[data-if=cpp],
*[data-if=c],
*[data-if=dotnet],
*[data-if=com],
*[data-if=python] {
    display: none;
}

.tabbar {
    text-align: right;
    border-bottom: 1px solid #f28d26;
    margin-bottom: 0.5em;
}

ul.tabs {
    padding-top: 3px;
    padding-bottom: 3px;
    margin-top: 10px;
    margin-bottom: 0;
    font-size: 80%
}

ul.tabs li {
    padding-top: 3px;
    padding-bottom: 3px;
    display: inline;
    overflow: hidden;
    list-style-type: none;
    margin: 0;
    margin-left: 8px;
    border-top: 1px solid #666;
    border-left: 1px solid #666;
    border-right: 1px solid #666;
}

ul.tabs li.active {
    border-left: 1px solid #f28d26;
    border-right: 1px solid #f28d26;
    border-top: 1px solid #f28d26;
    border-bottom: 1px solid #fff;
}

ul.tabs li.inactive {
    background-color: #eee;
}

ul.tabs li a {
    padding-left: 5px;
    padding-right: 5px;
    color: #666;
}

ul.tabs li a:link:hover {
    text-decoration: none;
}

ul.tabs li.inactive a {
    color: #666;
}

ul.tabs li.active a {
    color: black;
}

dl.generic dd {
    margin-bottom: 1em;
}

.pari {
    color: olive;
}

.paro {
    color: maroon;
}

.comment {
    font-size: 80%;
    color: green;
    white-space: nowrap;
}

table.grid {
    border-collapse: collapse;
}

table.grid td {
    padding: 5px;
    border: 1px solid;
}

table.layout {
    border: 0px;
}

table.layout td {
    padding: 5px;
}

table.table {
    border-collapse: collapse;
}

table.table td {
    padding: 5px;
    border-left: 0px;
    border-right: 0px;
}

table.table tr:last-child {
    border-bottom: 1px solid;
}

table.table th {
    padding: 5px;
    border-top: 1px solid;
    border-bottom: 1px solid;
    border-left: 0px;
    border-right: 0px;
}

.details_summary {
    cursor: pointer;
}

table.toctable {
    width: 100%;
}

table.toctable col:first-child {
    width: 20%;
}

table.toctable col:nth-last-child(2) {
    width: 8%;
}

table.altcolored tr:nth-child(even) {
    background-color: #f3f3f3;
}

    </style>
<!--OP_REF_STYLE_END-->
<script>
    <!--
var active_lang='hdevelop';function switchVisibility(obj,active_lang,new_lang)
{var display_style='inline';
for(var i=0;i<obj.length;i++)
{if(obj.item(i).getAttribute('data-if')==new_lang)
{obj.item(i).style.display=display_style;}
if(obj.item(i).getAttribute('data-if')==active_lang)
{obj.item(i).style.display='none';}}
return;}
function toggleLanguage(new_lang,initial)
{if(active_lang!=new_lang)
{var lis=document.getElementsByTagName('li');for(var i=0;i<lis.length;i++)
{if(lis.item(i).id=='syn-'+new_lang)
{lis.item(i).className='active';}
else
{lis.item(i).className='inactive';}}
var divs=document.getElementsByTagName('div');var spans=document.getElementsByTagName('span');switchVisibility(divs,active_lang,new_lang);switchVisibility(spans,active_lang,new_lang);if(!initial)
{setCookie("halcon_reference_language",new_lang,null,null);}
active_lang=new_lang;}
return;}
function setCookie(name,value,domain,exp_offset,path,secure)
{localStorage.setItem(name,value);}
function getCookie(name)
{return localStorage.getItem(name);}
function initialize()
{var qs=location.href.split('?')[1];var qs_lang_raw=location.href.split('interface=')[1];var qs_lang;if(qs_lang_raw)
{qs_lang=qs_lang_raw.split('#')[0];}
var cookie_lang=getCookie("halcon_reference_language");var new_lang;if((qs_lang=="hdevelop")||(qs_lang=="dotnet")||(qs_lang=="python")||(qs_lang=="cpp")||(qs_lang=="c"))
{new_lang=qs_lang;setCookie("halcon_reference_language",new_lang,null,null);}
else if((cookie_lang=="hdevelop")||(cookie_lang=="dotnet")||(cookie_lang=="python")||(cookie_lang=="cpp")||(cookie_lang=="c"))
{new_lang=cookie_lang;}
else
{new_lang="hdevelop";}
toggleLanguage(new_lang,1);return;}
-->

  </script>
</head>
<body onload="initialize();">
<div class="breadcrumb">
<br class="inv"><a href="index.html">目录</a> / <a href="toc_system.html">系统</a> / <a href="toc_system_serial.html">Serial</a><br class="inv">
</div>
<div class="body_main">
<div class="tabbar"><ul class="tabs">
<li id="syn-hdevelop" class="active"><a href="javascript:void(0);" onclick="toggleLanguage('hdevelop')" onfocus="blur()">HDevelop</a></li>
<li id="syn-dotnet" class="inactive"><a href="javascript:void(0);" onclick="toggleLanguage('dotnet')" onfocus="blur()">.NET</a></li>
<li id="syn-python" class="inactive"><a href="javascript:void(0);" onclick="toggleLanguage('python')" onfocus="blur()">Python</a></li>
<li id="syn-cpp" class="inactive"><a href="javascript:void(0);" onclick="toggleLanguage('cpp')" onfocus="blur()">C++</a></li>
<li id="syn-c" class="inactive"><a href="javascript:void(0);" onclick="toggleLanguage('c')" onfocus="blur()">C</a></li>
</ul></div>
<div class="indexlink">
<a href="index_classes.html"><span data-if="dotnet" style="display:none;">类别</span><span data-if="cpp" style="display:none;">类别</span></a><span data-if="dotnet" style="display:none;"> | </span><span data-if="cpp" style="display:none;"> | </span><a href="index_by_name.html">算子列表</a>
</div>
<!--OP_REF_HEADER_END-->
<h1 id="sec_name">
<span data-if="hdevelop" style="display:inline;">read_serial</span><span data-if="c" style="display:none;">T_read_serial</span><span data-if="cpp" style="display:none;">ReadSerial</span><span data-if="dotnet" style="display:none;">ReadSerial</span><span data-if="python" style="display:none;">read_serial</span> (算子名称)</h1>
<h2>名称</h2>
<p><code><span data-if="hdevelop" style="display:inline;">read_serial</span><span data-if="c" style="display:none;">T_read_serial</span><span data-if="cpp" style="display:none;">ReadSerial</span><span data-if="dotnet" style="display:none;">ReadSerial</span><span data-if="python" style="display:none;">read_serial</span></code> — Read from a serial device.</p>
<h2 id="sec_synopsis">参数签名</h2>
<div data-if="hdevelop" style="display:inline;">
<p>
<code><b>read_serial</b>( :  : <a href="#SerialHandle"><i>SerialHandle</i></a>, <a href="#NumCharacters"><i>NumCharacters</i></a> : <a href="#Data"><i>Data</i></a>)</code></p>
</div>
<div data-if="c" style="display:none;">
<p>
<code>Herror <b>T_read_serial</b>(const Htuple <a href="#SerialHandle"><i>SerialHandle</i></a>, const Htuple <a href="#NumCharacters"><i>NumCharacters</i></a>, Htuple* <a href="#Data"><i>Data</i></a>)</code></p>
</div>
<div data-if="cpp" style="display:none;">
<p>
<code>void <b>ReadSerial</b>(const HTuple&amp; <a href="#SerialHandle"><i>SerialHandle</i></a>, const HTuple&amp; <a href="#NumCharacters"><i>NumCharacters</i></a>, HTuple* <a href="#Data"><i>Data</i></a>)</code></p>
<p>
<code><a href="HTuple.html">HTuple</a> <a href="HSerial.html">HSerial</a>::<b>ReadSerial</b>(Hlong <a href="#NumCharacters"><i>NumCharacters</i></a>) const</code></p>
</div>
<div data-if="com" style="display:none;"></div>
<div data-if="dotnet" style="display:none;">
<p>
<code>static void <a href="HOperatorSet.html">HOperatorSet</a>.<b>ReadSerial</b>(<a href="HTuple.html">HTuple</a> <a href="#SerialHandle"><i>serialHandle</i></a>, <a href="HTuple.html">HTuple</a> <a href="#NumCharacters"><i>numCharacters</i></a>, out <a href="HTuple.html">HTuple</a> <a href="#Data"><i>data</i></a>)</code></p>
<p>
<code><a href="HTuple.html">HTuple</a> <a href="HSerial.html">HSerial</a>.<b>ReadSerial</b>(int <a href="#NumCharacters"><i>numCharacters</i></a>)</code></p>
</div>
<div data-if="python" style="display:none;">
<p>
<code>def <b>read_serial</b>(<a href="#SerialHandle"><i>serial_handle</i></a>: HHandle, <a href="#NumCharacters"><i>num_characters</i></a>: int) -&gt; Sequence[int]</code></p>
<p>
<code>def <b>read_serial_s</b>(<a href="#SerialHandle"><i>serial_handle</i></a>: HHandle, <a href="#NumCharacters"><i>num_characters</i></a>: int) -&gt; int</code></p>
</div>
<h2 id="sec_description">描述</h2>
<p><code><span data-if="hdevelop" style="display:inline">read_serial</span><span data-if="c" style="display:none">read_serial</span><span data-if="cpp" style="display:none">ReadSerial</span><span data-if="com" style="display:none">ReadSerial</span><span data-if="dotnet" style="display:none">ReadSerial</span><span data-if="python" style="display:none">read_serial</span></code> tries to read <a href="#NumCharacters"><i><code><span data-if="hdevelop" style="display:inline">NumCharacters</span><span data-if="c" style="display:none">NumCharacters</span><span data-if="cpp" style="display:none">NumCharacters</span><span data-if="com" style="display:none">NumCharacters</span><span data-if="dotnet" style="display:none">numCharacters</span><span data-if="python" style="display:none">num_characters</span></code></i></a> from the
serial device given in <a href="#SerialHandle"><i><code><span data-if="hdevelop" style="display:inline">SerialHandle</span><span data-if="c" style="display:none">SerialHandle</span><span data-if="cpp" style="display:none">SerialHandle</span><span data-if="com" style="display:none">SerialHandle</span><span data-if="dotnet" style="display:none">serialHandle</span><span data-if="python" style="display:none">serial_handle</span></code></i></a>.  The read characters
are returned in <a href="#Data"><i><code><span data-if="hdevelop" style="display:inline">Data</span><span data-if="c" style="display:none">Data</span><span data-if="cpp" style="display:none">Data</span><span data-if="com" style="display:none">Data</span><span data-if="dotnet" style="display:none">data</span><span data-if="python" style="display:none">data</span></code></i></a> as a tuple of integers.  This allows
to read NUL characters, which would otherwise be interpreted as the
end of a string.  If the timeout of the serial device has been set
to a value greater than 0 with <a href="set_serial_param.html"><code><span data-if="hdevelop" style="display:inline">set_serial_param</span><span data-if="c" style="display:none">set_serial_param</span><span data-if="cpp" style="display:none">SetSerialParam</span><span data-if="com" style="display:none">SetSerialParam</span><span data-if="dotnet" style="display:none">SetSerialParam</span><span data-if="python" style="display:none">set_serial_param</span></code></a>,
<code><span data-if="hdevelop" style="display:inline">read_serial</span><span data-if="c" style="display:none">read_serial</span><span data-if="cpp" style="display:none">ReadSerial</span><span data-if="com" style="display:none">ReadSerial</span><span data-if="dotnet" style="display:none">ReadSerial</span><span data-if="python" style="display:none">read_serial</span></code> waits at most as long for the arrival of the
first character as indicated by the timeout.  Otherwise, the
operator returns immediately.  In any case, the number of characters
available at the time of return are passed back to the caller, i.e.,
fewer characters than requested can be returned.  This can be
checked by the length of the tuple <a href="#Data"><i><code><span data-if="hdevelop" style="display:inline">Data</span><span data-if="c" style="display:none">Data</span><span data-if="cpp" style="display:none">Data</span><span data-if="com" style="display:none">Data</span><span data-if="dotnet" style="display:none">data</span><span data-if="python" style="display:none">data</span></code></i></a>.</p>
<h2 id="sec_execution">运行信息</h2>
<ul>
  <li>多线程类型:可重入(与非独占操作符并行运行)。</li>
<li>多线程作用域:全局(可以从任何线程调用)。</li>
  <li>未经并行化处理。</li>
</ul>
<h2 id="sec_parameters">参数表</h2>
  <div class="par">
<div class="parhead">
<span id="SerialHandle" class="parname"><b><code><span data-if="hdevelop" style="display:inline">SerialHandle</span><span data-if="c" style="display:none">SerialHandle</span><span data-if="cpp" style="display:none">SerialHandle</span><span data-if="com" style="display:none">SerialHandle</span><span data-if="dotnet" style="display:none">serialHandle</span><span data-if="python" style="display:none">serial_handle</span></code></b> (input_control)  </span><span>serial <code>→</code> <span data-if="dotnet" style="display:none"><a href="HSerial.html">HSerial</a>, </span><span data-if="dotnet" style="display:none"><a href="HTuple.html">HTuple</a></span><span data-if="python" style="display:none">HHandle</span><span data-if="cpp" style="display:none"><a href="HTuple.html">HTuple</a></span><span data-if="c" style="display:none">Htuple</span><span data-if="hdevelop" style="display:inline"> (handle)</span><span data-if="dotnet" style="display:none"> (<i>IntPtr</i>)</span><span data-if="cpp" style="display:none"> (<i>HHandle</i>)</span><span data-if="c" style="display:none"> (<i>handle</i>)</span></span>
</div>
<p class="pardesc">Serial interface handle.</p>
</div>
  <div class="par">
<div class="parhead">
<span id="NumCharacters" class="parname"><b><code><span data-if="hdevelop" style="display:inline">NumCharacters</span><span data-if="c" style="display:none">NumCharacters</span><span data-if="cpp" style="display:none">NumCharacters</span><span data-if="com" style="display:none">NumCharacters</span><span data-if="dotnet" style="display:none">numCharacters</span><span data-if="python" style="display:none">num_characters</span></code></b> (input_control)  </span><span>integer <code>→</code> <span data-if="dotnet" style="display:none"><a href="HTuple.html">HTuple</a></span><span data-if="python" style="display:none">int</span><span data-if="cpp" style="display:none"><a href="HTuple.html">HTuple</a></span><span data-if="c" style="display:none">Htuple</span><span data-if="hdevelop" style="display:inline"> (integer)</span><span data-if="dotnet" style="display:none"> (<i>int</i> / </span><span data-if="dotnet" style="display:none">long)</span><span data-if="cpp" style="display:none"> (<i>Hlong</i>)</span><span data-if="c" style="display:none"> (<i>Hlong</i>)</span></span>
</div>
<p class="pardesc">Number of characters to read.</p>
<p class="pardesc"><span class="parcat">Default:
      </span>1</p>
<p class="pardesc"><span class="parcat">Suggested values:
      </span>1, 2, 3, 4, 5, 10, 20, 40, 100</p>
</div>
  <div class="par">
<div class="parhead">
<span id="Data" class="parname"><b><code><span data-if="hdevelop" style="display:inline">Data</span><span data-if="c" style="display:none">Data</span><span data-if="cpp" style="display:none">Data</span><span data-if="com" style="display:none">Data</span><span data-if="dotnet" style="display:none">data</span><span data-if="python" style="display:none">data</span></code></b> (output_control)  </span><span>integer(-array) <code>→</code> <span data-if="dotnet" style="display:none"><a href="HTuple.html">HTuple</a></span><span data-if="python" style="display:none">Sequence[int]</span><span data-if="cpp" style="display:none"><a href="HTuple.html">HTuple</a></span><span data-if="c" style="display:none">Htuple</span><span data-if="hdevelop" style="display:inline"> (integer)</span><span data-if="dotnet" style="display:none"> (<i>int</i> / </span><span data-if="dotnet" style="display:none">long)</span><span data-if="cpp" style="display:none"> (<i>Hlong</i>)</span><span data-if="c" style="display:none"> (<i>Hlong</i>)</span></span>
</div>
<p class="pardesc">Read characters (as tuple of integers).</p>
</div>
<h2 id="sec_result">结果</h2>
<p>If the parameters are correct and the read from the device was
successful, 该算子 <code><span data-if="hdevelop" style="display:inline">read_serial</span><span data-if="c" style="display:none">read_serial</span><span data-if="cpp" style="display:none">ReadSerial</span><span data-if="com" style="display:none">ReadSerial</span><span data-if="dotnet" style="display:none">ReadSerial</span><span data-if="python" style="display:none">read_serial</span></code> 返回值 <TT>2</TT> (
      <TT>H_MSG_TRUE</TT>)
    .
Otherwise an exception is raised.</p>
<h2 id="sec_predecessors">可能的前置算子</h2>
<p>
<code><a href="open_serial.html"><span data-if="hdevelop" style="display:inline">open_serial</span><span data-if="c" style="display:none">open_serial</span><span data-if="cpp" style="display:none">OpenSerial</span><span data-if="com" style="display:none">OpenSerial</span><span data-if="dotnet" style="display:none">OpenSerial</span><span data-if="python" style="display:none">open_serial</span></a></code>
</p>
<h2 id="sec_see">参考其它</h2>
<p>
<code><a href="write_serial.html"><span data-if="hdevelop" style="display:inline">write_serial</span><span data-if="c" style="display:none">write_serial</span><span data-if="cpp" style="display:none">WriteSerial</span><span data-if="com" style="display:none">WriteSerial</span><span data-if="dotnet" style="display:none">WriteSerial</span><span data-if="python" style="display:none">write_serial</span></a></code>
</p>
<h2 id="sec_module">模块</h2>
<p>
Foundation</p>
<!--OP_REF_FOOTER_START-->
<hr>
<div class="indexlink">
<a href="index_classes.html"><span data-if="dotnet" style="display:none;">类别</span><span data-if="cpp" style="display:none;">类别</span></a><span data-if="dotnet" style="display:none;"> | </span><span data-if="cpp" style="display:none;"> | </span><a href="index_by_name.html">算子列表</a>
</div>
<div class="footer">
<div class="copyright">HALCON算子参考手册 Copyright © 2015-2023 51Halcon</div>
</div>
</div>
</body>
</html>
